<template>
  <div class="register-container">
    <div style="width: 400px;height: 450px;margin:110px auto;background-color: rgba(149,220,146,0.91);border-radius: 10px">
      <div style="width: 100%;height: 100px;font-size: 30px;line-height: 100px;text-align: center;color: #157342">请先注册</div>
      <div style="margin-top: 25px;text-align: center;height: 320px">
        <el-form :model="admin">
          <el-form-item>
            <el-input v-model="admin.name" prefix-icon="el-icon-user" style="width: 80%" placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="admin.password" prefix-icon="el-icon-user" style="width: 80%" placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-select v-model="admin.grade" placeholder="请选择年级"style="width: 80%">
              <el-option label="高一" value="高一"></el-option>
              <el-option label="高二" value="高二"></el-option>
              <el-option label="高三" value="高三"></el-option>
            </el-select>
            <el-input v-model="admin.classes" placeholder="请选择班级" autocomplete="off" style="width: 80%"></el-input>
          </el-form-item>
          <el-form-item>
            <template >
              <el-radio v-model="admin.sex" label="男">男</el-radio>
              <el-radio v-model="admin.sex" label="女">女</el-radio>
            </template>
          </el-form-item>
          <el-form-item>
            <el-button style="width: 40%;margin-top: 10px" type="success" @click="turnlog()">返回登录</el-button>
            <el-button style="width: 40%;margin-top: 10px" type="success" @click="register()">注册</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>

import request from "@/utils/request";

export default {
  name:"Register",
  data() {
    return {
      admin:{role:"学生"},
      formLabelWidth:"10%",
    }
  },
  created() {
  },
  methods:{
    turnlog(){
      this.$router.push("/login");
    },
    register(){
      request.post("/admin/register",this.admin).then(res=>{
        if(res.code==='0'){
          this.$message({
            message: '注册成功',
            type: 'success'
          });
          this.$router.push("/login");
        }else{
          this.$message.error({
            message: res.msg,
            type: 'error'
          })
        }
      })
    }
  }
}
</script>

<style scoped>
.register-container{
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw; /* 100% of viewport width */
  height: 100vh; /* 100% of viewport height */
  overflow: hidden;
  background-image: url("@/assets/封面2.jpg");
  background-size: cover;
  display: flex;
  align-content: center;
  justify-content: center;
}
</style>